<include file="Common:header"/>
<style>
.progress{position:relative; margin-top:45px;width:200px;padding: 1px; border-radius:3px; display:block}
.bar {background-color: green; display:block; width:0%; height:20px;border-radius:3px; }
.botton_s{float:left;width:49%;text-align:center;height:40px;line-height:40px;font-size:17px;border-right:1px solid #DADADA;}
.size{width:50%;height:120px;float:left;}
.input_t{height:30px;float:right;width:75%;margin:0px;border:none;margin-top:1px;border-radius:0px;}
.p_class{float:left;width:23%;height:34px;line-height:34px;text-align:center}
.word_style{border-top:1px solid #DADADA;border-bottom:1px solid #DADADA;width:100%;height:34px;margin:0px;margin-top:20px}
.up_img{margin:0px;margin-top:20px;width:100%;border-top:1px solid #DADADA;border-bottom:1px solid #DADADA;height:120px}
.up_img_p{text-align:center;line-height:120px;font-size:35px;width:50%;float:right;height:120px;}
.img_div{width:60%;height:150px;border:1px solid #DADADA;margin:0 auto;position:absolute;top:0px;left:23%;background-color:white}
.upload{width:100%;height:110px;border-bottom:1px solid #DADADA;text-align:center;line-height:110px;font-size:25px;}
</style>
<body>
	<div class="edit_con">
		<div class="bannerbaowei">
			<div class="dajianxi"></div>
			<div class="tit1h4391">设置图片广告</div>
		</div>
		<div class="edit_area">
				<div class="word_style" >
					<p class="p_class">广告文字：</p>
					<input type="text"  name="title" class="input_t" value="<{$ad['title']}>" >
				</div>

				<div class="clear"></div>
				
				<div class="word_style">
					<p class="p_class">点击模式：</p>
					<select class="input_t" name="type" style="height:32px" >
						<option value="1" <if condition="$ad['type'] eq 1"> selected="selected" </if>>链接</option>
						<option value="4" <if condition="$ad['type'] eq 4"> selected="selected" </if>>电话</option>
						<option value="5" <if condition="$ad['type'] eq 5"> selected="selected" </if>>电话跟链接</option>
					</select>
				</div>

				<div style="position:relative">

				<div class="clear"></div>

				<div class="word_style" id="line">
					<p class="p_class">链接地址：<!-- （点击广告跳转到此地址） --></p>
					<input type="text" name="url" class="input_t"  value="<{$ad['url']}>" ><!-- class="link_write" -->
					<!-- <div class="link_btn">
						<p class="add_link"  onclick="popularize_url()">插入推广链接</p>
						<p class="clear_link" onclick="clear_link()">清空网址</p>
					</div> -->
				</div>

				<div class="clear"></div>

				<div class="word_style" id="phone">
					<p class="p_class">电话：</p>
					<input type="text" name="phone" class="input_t" value="<{$ad['phone']}>" >
				</div>

				<div class="clear"></div>

				</div>

				<div class="clear"></div>
			<if condition="($status) OR ($user_info['level'] NEQ 0)">
				<div class="up_img" >
						<!-- 用来激活上传图片插件 -->
						<botton class="botton_s"  id="select_dom" style="display:none">上传图片</botton>
						<!-- <input type="file" name="picture" id="file" onchange="btn_submit()" style="display:none"> -->
						<!-- <p class="clear_word" onclick="clear_picture(this)" >删除图片</p> -->
						<div class="size">
							<img id="show_img"  src="<{$ad['thumb']}>" style="width:100%;height:100%">
						</div>
						<p class="up_img_p">上传图片</p>
						<{:A('Upload')->upload_tool('select_dom','show_img','true')}>
				</div>

				<div class="clear"></div>

				<div class="word_style" style="margin-top:30px">
					<p class="p_class">按钮类型：</p>
					<select class="input_t" name="button_type" style="height:32px" name="type">
						<option value="0" <if condition="empty($ad['button_type'])"> selected="selected" </if>>无</option>
						<option value="1" <if condition="$ad['button_type'] == 1"> selected="selected" </if>>悬浮</option>
					</select>
				</div>

				<div class="word_style" id="position_type" style="margin-top:30px;display:none">
					<p class="p_class">按钮位置：</p>
					<select class="input_t" name="button_position" style="height:32px" name="type">
						<option value="0" <if condition="empty($ad['button_position'])"> selected="selected" </if>>顶部</option>
						<option value="1" <if condition="$ad['button_position'] == 1"> selected="selected" </if>>底部</option>
					</select>
				</div>

			<else />
			<div class="banner_word" style="margin-top:55px">
				<p>上传图片是付费会员的功能，您的试用已经到期</p>
					<p class="clear_word" onclick="return false;" style="background-color:#BAB8B8;">删除图片</p>
					<p class="clear_word" onclick="return false;" style="background-color:#BAB8B8;margin-right:5px;">选择图片</p>
					<p class="clear_word" onclick="jump()" style="width:130px;background-color:#2ebc82;margin-right:2px;">付费成为会员</p>
			</div>
			</if>

				<div class="clear"></div>
				<div class="btn_area" style="margin-bottom:50px">
					<input style="width:100%" type="button" onclick="commit(this)" class="banner_sub" value="提交" style="text-align:center">
					<input type="hidden" value="<{$ad['id']}>" id="tid">
					<input type="hidden" id ="upload" value="<{$ad['thumb']}>">
					<input type="hidden" id ="library" value="<{$ad['img_id']}>">
				</div>
			<!-- <p class="count_area">总点击数：0   今日点击数：0</p> -->
		</div>
		<include file="Common:menu"/>
	</div>
	<{:A('Template')->library()}>
</body>
</html>
<script>
	$(function(){
		var type_val = "<{$ad['type']}>";
		
		if(type_val == ''){
			$("#line").show();
			$("#phone").hide();
		}
		
		
		if(type_val == 4){
			$("#line").hide();
			$("#phone").show();
		}

		if(type_val == 5){
			$("#line").show();
			$("#phone").show();
		}

		if(type_val == 1){
			$("#line").show();
			$("#phone").hide();
		}

	})


	//切换模式
	$("select[name='type']").change(function(){
		var type_val = $(this).val();

		//电话跟链接
		if(type_val == 4){
			$("#line").hide();
			$("#phone").show();
		}

		if(type_val == 5){
			$("#line").show();
			$("#phone").show();
		}

		if(type_val == 1){
			$("#line").show();
			$("#phone").hide();
		}
		
	});

	$("select[name='button_type']").change(function(){
		var type_val = $(this).val();

		//悬浮按钮模型
		if(type_val == 0){
			$('#position_type').hide();
		}

		if(type_val == 1){
			$('#position_type').show();
		}

		if(type_val == 5){
			$("#line").show();
			$("#phone").show();
		}	
	})

	//显示图片
	$(".up_img_p").click(function(){
		layer.open({
		    content: '请选择上传图片方式',
		    btn: ['上传图片', '图片库'],
		    shadeClose: true,
		    yes: function(){
		    	$("#select_dom").click();
		        layer.closeAll();
		    }, no: function(){
		    	$(".text_library").show();
		        layer.closeAll();
		    }
		});

	})

	
	//提交
	function commit(obj){
		var title = $('input[name="title"]').val();
		var url   = $('input[name="url"]').val();
		var tid   = $('#tid').val();
		var image = $('#upload').val();
		var button_type = $('select[name="button_type"]  option:selected').val();
		var button_position = $('select[name="button_position"]  option:selected').val();
		var type = $('select[name="type"]  option:selected').val();
		var phone = $('input[name="phone"]').val();
		var library =$('#library').val();

		if($(obj).attr('readonly')){
			return false;
		}

		$(obj).attr('readonly','readonly');
		url = base64en(url);
		phone = base64en(phone);
		
		$.ajax({
		   type: "POST",
		   url: "<{:U('Home/Template/ajax_word')}>",
		   data: "title="+title+"&url="+url+"&id="+tid+"&button_type="+button_type+"&button_position="+button_position+"&thumb="+image+"&type="+type+"&phone="+phone+"&library="+library,
		   success: function(msg){
				if(msg.status == '1'){
					layer.open({
						content:'广告保存成功',
						btn: ['确认'],
						yes:function(){
						   window.location.href = msg.url;
						}
					});
			    }else{
					layer.open({
						content:msg.msg
					});
				}
				$(obj).removeAttr('readonly');
		   }
		});
	}

	//清空文字
	function clear_word(){
		$('input[name="title"]').val('');
	}

	//清除链接
	function clear_link(){
		$('input[name="url"]').val('');
	}

	
	//清楚图片
	function clear_picture(obj){
		$('#upload').val('');
		$(obj).parent().find('img').attr('src','');
	}

	//推广链接
	function popularize_url(){
		var popularize_url = "<{$member_info['spread_url']}>";
		$('input[name="url"]').val(popularize_url);
	}

	//按钮位置
	function position_type_show(){
		$('#position_type').show();
	}

	//按钮位置
	function position_type_hide(){
		$('#position_type').hide();
	}

	
	//不是会员点击跳转
	function jump(){
		window.location.href="<{:U('Home/User/upgrade')}>";
		return false;
	}

	<if condition="$ad['button_type'] == '1'">
		$('#position_type').show();
	</if>

</script>
